angular.module('app').controller('orderlistCtrl', 
['$scope', '$rootScope', 'http', 'stateV', '$state',
function($scope, $rootScope, http, stateV, $state) 
{
	$scope.query = {status:'', type:'', pages:0, total:0, totalPages:0};

	$scope.collect = {
		search: function(){
			$scope.query.pages = 0;
			list();
		},
		reset: function(){
			$scope.query.status = '1';
			$scope.query.type = '';
		},
		prePage: function(){
			if($scope.query.pages >= 1){
				--$scope.query.pages
				list();
			}
		},
		nextPage: function(){
			if(($scope.query.pages+1) < $scope.query.totalPages){
				++$scope.query.pages
				list();
			}
		},
		showPage: function(num){
			if((switchPage($scope.query.pages) + num) < $scope.query.totalPages)
				return true
			else
				return false
		},
		showPageVal: function(num){
			return switchPage($scope.query.pages) + num;
		}
	};

	$scope.delete = function(orderid){
		http.get(globalConfig.web+'/order/cancelOrder?orderid='+orderid, function(data, status){
			if(status==200){
				alert('删除成功，请手动刷新列表')
			}
		})
	}
	

	$scope.detail = function(detail){
		stateV.set(detail)
		$state.go('orderdetail');
	}

	function list(){
		var reqUrl = globalConfig.web + '/order/list';
		http.post(reqUrl, $scope.query, function(data, status){
			$scope.query.total = data.count;
			$scope.query.totalPages = totalPage($scope.query.total);
			$scope.orderList = data.list; 
		})
	}

	list();	
	
}]);